<template>
  <div class="loginCont">
    <img src="/img/banner.png" />
    <div class="maskCont">
      <div class="maskMain">
        <div class="maskRight">
          <div class="maskTop">
            <div class="maskName">渠道网点授权系统</div>
            <div class="maskDes">Channel network authorization platform</div>
          </div>
          <div class="formEnter">
            <div class="inputCont">
              <div class="inputName">Account(账号)</div>
              <div class="inputVal">
                <el-input
                  v-model="account"
                  type="text"
                  size="large"
                  placeholder="Enter your Account"
                ></el-input>
              </div>
            </div>
            <div class="inputCont">
              <div class="inputName">Password(密码)</div>
              <div class="inputVal">
                <el-input
                  v-model="password"
                  type="password"
                  size="large"
                  show-password
                  placeholder="Enter your password"
                ></el-input>
              </div>
            </div>
            <div class="underCont">
              <div class="checkCont">
                <el-checkbox v-model="remenberPassword" />
                <span>记住密码</span>
              </div>
              <div class="tipText">
                <span>没有账号？</span>
                <span class="linkText" @click="registFn">联系管理员</span>
              </div>
            </div>
            <el-button
              type="primary"
              :loading="logining"
              :disabled="logining"
              style="width: 100%; line-height: 50px; height: 40px"
              @click="loginFn"
              >{{ logining ? "正在登录" : "登录" }}</el-button
            >
          </div>
        </div>
      </div>
    </div>
    <div class="rightCont">
      <div class="iconfont icon-dianhua2"></div>
      <div class="rightMask maskTel">400-115-9966</div>
    </div>
  </div>
</template>

<script>
import { login } from "@/http/api";
import { ElMessage, ElMessageBox } from "element-plus";

export default {
  components: {},
  data() {
    return {
      logining: false,
      account: "",
      password: "",
      remenberPassword: false,
    };
  },
  props: {},
  methods: {
    loginFn() {
      if (this.account == "") {
        ElMessage({
          message: "请输入账号",
          type: "warning",
        });
        return false;
      } else if (this.password == "") {
        ElMessage({
          message: "请输入密码",
          type: "warning",
        });
        return false;
      }
      var data = {
        username: this.account,
        password: this.password,
      };
      this.logining = true;
      login(data)
        .then((res) => {
          if (res.data.code == 1) {
            let resData = res.data.data;
            localStorage.setItem("channel_token", resData.token);
            localStorage.setItem(
              "channel_partner_name",
              resData.channel_partner_name
            );

            // 记住密码
            if (this.remenberPassword) {
              localStorage.setItem("account", this.account);
              localStorage.setItem("password", this.password);
            } else {
              localStorage.setItem("account", "");
              localStorage.setItem("password", "");
            }
            localStorage.setItem("remenberPassword", this.remenberPassword);
            ElMessage({
              message: "登陆成功",
              type: "success",
            });
            setTimeout(() => {
              this.logining = false;
              this.$router.push({ path: "/home" });
            }, 1500);
          } else {
            setTimeout(() => {
              this.logining = false;
            }, 500);
            ElMessage(res.data.msg);
          }
        })
        .catch((err) => {
          ElMessage("服务器请求超时");
          setTimeout(() => {
            this.logining = false;
          }, 500);
        });
    },
    registFn() {
      ElMessageBox.confirm(
        "请联系管理员注册账号(管理员电话：400-115-9966)",
        "操作提示",
        {
          confirmButtonText: "确认",
          cancelButtonText: "取消",
          type: "Warning",
        }
      )
        .then(() => {})
        .catch((err) => {});
    },
  },
  mounted() {},
  created() {
    if (localStorage.getItem("remenberPassword") === "true") {
      this.account = localStorage.getItem("account");
      this.password = localStorage.getItem("password");
      this.remenberPassword = true;
    }
  },
};
</script>

<style scoped lang="less">
.loginCont {
  width: 100%;
  height: 100vh;
  overflow: hidden;
  position: relative;
  background-color: #f0f1fb;
  img {
    width: 100%;
  }
  .maskCont {
    width: 100%;
    position: absolute;
    height: 100%;
    // background-color: rgba(0, 0, 0, 0.3);
    left: 0;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 100px;
    box-sizing: border-box;
    .maskMain {
      background-image: linear-gradient(
        to bottom,
        #add6ff,
        #fff,
        #fff,
        #fff,
        #fff
      );
      width: 450px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      border-radius: 10px;
      overflow: hidden;

      .maskRight {
        flex: 1;
        width: 100px;
        padding: 30px 30px 40px;
        box-sizing: border-box;
        .maskTop {
          width: 100%;
          .maskName {
            font-size: 25px;
            font-weight: bold;
          }
          .maskDes {
            color: #333;
            font-weight: bold;
            margin: 5px 0 20px;
          }
        }
        .formEnter {
          .inputCont {
            width: 100%;
            margin-bottom: 25px;
            .inputName {
              margin-bottom: 10px;
            }
            .inputVal {
              display: flex;
              .phoneInput {
                width: 50px;
                flex: 1;
              }
            }
          }
          .underCont {
            width: 100%;
            display: flex;
            justify-content: space-between;
            align-items: center;
            font-size: 12px;
            color: #999;
            margin-bottom: 10px;
            .checkCont {
              display: flex;
              align-items: center;
              span {
                margin-left: 5px;
              }
            }
            .tipText {
              text-align: right;

              .linkText {
                text-decoration: underline;
                cursor: pointer;
              }
              .linkText:hover {
                color: #409eff;
              }
            }
          }
        }
      }
    }
  }
  .rightCont {
    position: absolute;
    top: 30px;
    right: 30px;
    background-color: #e1ecfd;
    display: flex;
    padding: 10px 20px;
    border-radius: 50px;
    .iconfont {
      margin-right: 5px;
      color: #0080ff;
    }
  }
}
</style>
